package com.diudiutechnology.www.yadiudiu.util.utils;

import android.app.AlertDialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.diudiutechnology.www.yadiudiu.R;

/**
 * Created by Administrator on 2017/8/15.
 */

public class Dialog {
    /**
     *
     * @param context 类
     * @param simg 提示内容
     * @param prom 提示标题
     * @param clickok 确定
     *@param okste 确定文字
     * @param onste 取消文字
     * @return
     */
    public static AlertDialog phonedialog(final Context context,
                                          final String simg , String prom, View.OnClickListener clickok ,String okste,String onste) {
        final AlertDialog alertDialog = new AlertDialog.Builder(context,R.style.dialog)
                .create();
        alertDialog.show();
        Window window = alertDialog.getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.dimAmount = 0.5f;
        window.setGravity(Gravity.CENTER);
        window.setLayout(Utils.getScreenWidth(context),
                Utils.getScreenHeight(context));
        window.setContentView(R.layout.phone);
        LinearLayout layout = (LinearLayout) window
                .findViewById(R.id.phone_top);
        TextView phone = (TextView) window.findViewById(R.id.phone);
        TextView prompting = (TextView) window.findViewById(R.id.prompting);

        TextView phonet = (TextView) window
                .findViewById(R.id.phonet);
        TextView phonef = (TextView) window
                .findViewById(R.id.phonef);


        phonet.setText(onste);
        phonef.setText(okste);
        if (simg.equals("")){
            phone.setVisibility(View.GONE);
        }else {
            phone.setVisibility(View.VISIBLE);
            phone.setText(simg);
        }
        if (prom.equals("")){
            prompting.setVisibility(View.GONE);
        }else {
            prompting.setVisibility(View.VISIBLE);
            prompting.setText(prom);
        }
        phonet.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub

                alertDialog.dismiss();
            }
        });
        phonef.setOnClickListener(clickok);
        layout.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub

                alertDialog.dismiss();
            }
        });
        return alertDialog;

    }
}
